﻿using System;
using Common.Modules;
using Common.Objects.Enums;
using EYCmsAdmin.Domain.Models;
using EYCmsAdmin.Presentation.Models.UserModels;

namespace EYCmsAdmin.Presentation.Mappers
{
    public static class UserMapper
    {
        public static void MapTo(this UserEditModel source, User user)
        {
            user.Email = source.Email;
            user.Id = source.Id;
            user.IsDeactivated = source.IsDeactivated;
            user.IsDeleted = source.IsDeleted;
            user.Login = source.Login;
            if (source.Id != 0)
            {
                user.Password = source.Password;
            }
            else
            {
                user.PasswordSalt = Security.CreateSalt();
                user.Password = Security.CreateHashedPassword(source.Password, user.PasswordSalt);
            }

            user.UserInfo.DateBirth = Convert.ToDateTime(source.DateBirth);
            user.UserInfo.Gender = (GenderTypes)source.GenderId;
            user.UserInfo.Name = source.Name;
            user.UserInfo.Surname = source.Surname;
        }
    }
}